# pylint: disable-msg=W0232
"""
@author: Sergiy Tsymbalyuk
"""

from sqlalchemy import Column, ForeignKey
from sqlalchemy.types import String, Boolean, Integer, Text, DateTime, Enum
from sqlalchemy.orm import relation

from pylons.i18n import lazy_ugettext as _

from chowa.model.meta import Base, Session
from chowa.model.auth import User

__all__ = ['Topic', 'Comment']

class Topic(Base):
    __tablename__ = 'social_topic'
    
    id = Column(Integer, primary_key=True)
    title = Column(String(100))
    url = Column(String(255))
    created = Column(DateTime)


class Comment(Base):
    __tablename__ = 'social_comment'
    
    id = Column(Integer, primary_key=True)
    text = Column(Text)
    created = Column(DateTime)
    user_id = Column(Integer, ForeignKey(User.id))
    topic_id = Column(Integer, ForeignKey(Topic.id))
    reply_to = Column(Integer)
    
    user = relation(User)
    topic = relation(Topic)
    
    
def comment_replies(comment):
    query = Session.query(Comment).filter_by(reply_to=comment.id)
    return query.all()

Comment.replies = comment_replies
        